package com.javacoo.swing.jxbrowser.content;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import com.javacoo.swing.jxbrowser.BaseBrowser;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.DefaultLoadHandler;
import com.teamdev.jxbrowser.chromium.LoadParams;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

/**
 * 处理加载
 * <li></li>
 * JxBrowser API提供了可用于处理加载的功能，并决定是否应在Chromium引擎中加载指定的URL。以下示例演示如何注册LoadHandler并取消导航到以http://www.google开头的所有URL
 * @author: duanyong@jccfc.com
 * @since: 2020/9/25 10:36
 */
public class HandlingLoading extends BaseBrowser {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView view = new BrowserView(browser);

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        browser.setLoadHandler(new DefaultLoadHandler() {
            @Override
            public boolean onLoad(LoadParams params) {
                return params.getURL().startsWith("https://gitee.com");
            }
        });
        browser.loadURL(BASE_URL);
    }
}
